package com.hy.frame.base;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.hy.frame.common.ILifeUI;


/**
 * title SuperActivity
 * author HeYan
 * time 2021/1/26 17:47
 * desc 不要写与具体项目相关的代码
 */
public abstract class SuperActivity extends AppCompatActivity implements ILifeUI {

    public <T extends View> T findViewById(int id, View parent) {
        if (parent != null) return parent.findViewById(id);
        return findViewById(id);
    }

    /**
     * 初始化Window相关参数，在super.onCreate(savedInstanceState);方法前
     */
    protected abstract void initWindow();

    /**
     * 初始化基础属性，返回false不会初始化布局
     */
    protected abstract boolean initAttrs();

    /**
     * 初始化布局，比如setContentView
     */
    protected abstract void initLayout();

    /**
     * 初始化控件
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        initWindow();
        super.onCreate(savedInstanceState);
        if (!initAttrs()) return;
        initLayout();
        initView();
        initData();
    }

    @NonNull
    public Context getContext() {
        return this;
    }

    /**
     * Called when pointer capture is enabled or disabled for the current window.
     *
     * @param hasCapture True if the window has pointer capture.
     */
    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}
